package com.dxy.chatserver.db.entity;

import cn.hutool.json.JSONUtil;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class AcceptLineMsgResponse{

    /**
     * 会话id
     */
    private String sessionId;

    /**
     * 是否为群聊消息：0-单聊，1-群聊
     */
    private Integer isRoomChat;

    private Integer type;

    private String content;

    private String msgId;

    private Long createTime;

    private AcceptLineMsgResponseUser fromUser;

    private AcceptLineMsgResponseUser toUser;

    private AcceptLineMsgResponseBodies bodies;

    /**
     * 状态：0-禁用，1-可用，2-撤回
     */
    private Integer status;

    public AcceptLineMsgResponse() {
        this.status = 1;
    }

    public static List<AcceptLineMsgResponse> build(List<EsOnlineMessageBuild> onlineMessageBuilds){
        if(onlineMessageBuilds.isEmpty()){
            return null;
        }
        List<AcceptLineMsgResponse> list =new ArrayList<>();
        onlineMessageBuilds.forEach(o->{
            AcceptLineMsgResponse response = new AcceptLineMsgResponse();
            response.setMsgId(o.getMsgId());
            response.setSessionId(o.getSessionId());
            response.setCreateTime(o.getCreateTime());
            response.setContent(o.getContent());
            response.setType(o.getType());
            response.setFromUser(JSONUtil.toBean(o.getFromUser(),AcceptLineMsgResponseUser.class));
            response.setToUser(JSONUtil.toBean(o.getToUser(),AcceptLineMsgResponseUser.class));
            response.setBodies(JSONUtil.toBean(o.getBodies(),AcceptLineMsgResponseBodies.class));
            response.setStatus(o.getStatus());
            response.setIsRoomChat(o.getIsRoomChat());
            list.add(response);
        });
        return list;
    }
}

